mcN = "letter";

increments = Math.floor(3600 / speed);

if (increments == 0)
   increments = 1;

alphaInc = (100 - alpha) / increments;
scaleInc = (100 - scale) / increments;
posInc   = top           / increments;

aLetters = new Array();

for (i = 0; i< numChar; i++)
{
  aLetters[i+0] = i;
  var letter =  this[mcN +i];
  letter._visible = false;
  letter.init = letterInit;
  letter.doEffect = effect;
  letter.number = i;
}

function letterInit()
{
  this._visible = true;
  this.step = 0;
  this.increments = this._parent.increments;
  this._alpha     = this._parent.alpha;
  this.alphaInc   = this._parent.alphaInc;
  this.scaleInc   = this._parent.scaleInc;
  this.posInc     = this._parent.posInc;
  this.finalX     = this._x;
  this.finalY     = this._y;

  this.scale = this._parent.scale;

  dir = Math.floor(3.99 * Math.random());

  this.xInc = 0;
  this.yInc = 0;

  if (dir == 0) // from left
  {
     this._x   = this._x - this._parent.top;
     this.xInc = this.posInc;
  }
  else if (dir == 1) // from top
  {
     this._y   = this._y - this._parent.top;
     this.yInc = this.posInc;
  }
  else if (dir == 2) // from right
  {
     this._x   = this._x + this._parent.top;
     this.xInc = -this.posInc;
  }
  else if (dir == 3) // from bottom
  {
     this._y   = this._y + this._parent.top;
     this.yInc = -this.posInc;
  }

  this.angle1 = 720 * Math.random() - 360;
  this.angle2 = 720 * Math.random() - 360;

  this.angle1Inc = (0 - this.angle1) / this.increments;
  this.angle2Inc = (0 - this.angle2) / this.increments;

  // inner movie clip
  this.letter._rotation = -45;

  this._rotation = (this.angle1 + this.angle2) * .5 + 45;

  radian = 3.1416 / 180;

  angle1Rad = this.angle1 * radian;
  angle2Rad = this.angle2 * radian;

  sin45 = Math.sin(45 * radian);

  sinAngles = Math.sin(((this.angle1 + this.angle2) * .5 + 45) * radian);

  if (sinAngles == 0)
    sinAngles = 1;

  this._xscale = this.scale * (Math.cos(angle1Rad) + Math.sin(angle2Rad)) * sin45 / sinAngles;

  this._yscale = this.scale * (Math.sin(angle1Rad) + Math.cos(angle2Rad)) * sin45 / sinAngles;
}

function effect()
{
  this._x      += this.xInc;
  this._y      += this.yInc;

  this._alpha  += this.alphaInc;
  this.scale   += this.scaleInc;

  this.angle1 += this.angle1Inc;
  this.angle2 += this.angle2Inc;

  this._rotation = (this.angle1 + this.angle2) * .5 + 45;

  radian = 3.1416 / 180;

  angle1Rad = this.angle1 * radian;
  angle2Rad = this.angle2 * radian;

  sin45 = Math.sin(45 * radian);

  sinAngles = Math.sin(((this.angle1 + this.angle2) * .5 + 45) * radian);

  if (sinAngles == 0)
    sinAngles = 1;

  this._xscale = this.scale * (Math.cos(angle1Rad) + Math.sin(angle2Rad)) * sin45 / sinAngles;

  this._yscale = this.scale * (Math.sin(angle1Rad) + Math.cos(angle2Rad)) * sin45 / sinAngles;

  this.step += 1;

  if (this.step >= this.increments)
  {
    this._xscale = 100;
    this._yscale = 100;
    this._rotation = 45;
    this._alpha  = 100;
    this._x      = this.finalX;
    this._y      = this.finalY;
    this.gotoAndStop("end");
  }
}

function shuffle()
{
  return Math.floor(Math.random() * 3) -1;
}

if (random == 1)
{
  aLetters.sort(shuffle);
}

if (reverse == 1)
{
  aLetters.reverse();
}